import axios from 'axios'
import Vue from 'vue'
// axios.defaults.baseURL = 'http://192.168.120.63:80/'
axios.defaults.baseURL = 'http://localhost:80/'
axios.interceptors.response.use(function(response) {
        if (response.data.coed == '5001') {
            localStorage.removeItem("jwt")
            router.push("/")
        } else {
            return response;
        }
    })
    // axios.defaults.withCredentials = false
    //添加拦截器，每次请求携带token
axios.interceptors.request.use(function(config) {
        //从localStore获取到jwt
        const token = localStorage.getItem('jwt')
            //将jwt作为名为auth_token的header传给后端
        config.headers.auth_token = token
        return config
    })
    //将axios绑定到vue全局变量
Vue.prototype.$http = axios
export default axios